@@ -1,6 +1,7 @@ |
||
| 1 | 1 |
# -*- coding: utf-8 -*- |
| 2 | 2 |
|
| 3 | 3 |
from django.conf.urls import url |
| 4 |
+from django_we import views as we_views |
|
| 4 | 5 |
|
| 5 | 6 |
from account import views as account_views |
| 6 | 7 |
from account import tourguide_views |
@@ -15,7 +16,6 @@ from operation import views as op_views |
||
| 15 | 16 |
from pay import views as pay_views |
| 16 | 17 |
from photo import views as photo_views |
| 17 | 18 |
from server import server_views |
| 18 |
-from wechat import views as wechat_views |
|
| 19 | 19 |
|
| 20 | 20 |
|
| 21 | 21 |
# 帐户相关 |
@@ -165,14 +165,14 @@ urlpatterns += [ |
||
| 165 | 165 |
|
| 166 | 166 |
# 微信授权相关 |
| 167 | 167 |
urlpatterns += [ |
| 168 |
- url(r'^wx_oauth2$', wechat_views.wx_oauth2, name='wx_oauth2'), |
|
| 169 |
- url(r'^base_redirect$', wechat_views.base_redirect, name='base_redirect'), |
|
| 170 |
- url(r'^userinfo_redirect$', wechat_views.userinfo_redirect, name='userinfo_redirect'), |
|
| 168 |
+ url(r'^wx_oauth2$', we_views.we_oauth2, name='we_oauth2'), |
|
| 169 |
+ url(r'^base_redirect$', we_views.base_redirect, name='base_redirect'), |
|
| 170 |
+ url(r'^userinfo_redirect$', we_views.userinfo_redirect, name='userinfo_redirect'), |
|
| 171 | 171 |
] |
| 172 | 172 |
|
| 173 | 173 |
# 微信分享相关 |
| 174 | 174 |
urlpatterns += [ |
| 175 |
- url(r'^wx/jsapi_signature$', wechat_views.wx_jsapi_signature_api, name='wx_jsapi_signature_api'), # jsapi_signature |
|
| 175 |
+ url(r'^wx/jsapi_signature$', we_views.we_jsapi_signature_api, name='we_jsapi_signature_api'), # jsapi_signature |
|
| 176 | 176 |
] |
| 177 | 177 |
|
| 178 | 178 |
# 首页相关 |
@@ -42,8 +42,9 @@ INSTALLED_APPS = ( |
||
| 42 | 42 |
'django.contrib.messages', |
| 43 | 43 |
'django.contrib.staticfiles', |
| 44 | 44 |
'rest_framework', |
| 45 |
- 'django_rlog', |
|
| 46 | 45 |
'django_q', |
| 46 |
+ 'django_rlog', |
|
| 47 |
+ 'django_we', |
|
| 47 | 48 |
'api', |
| 48 | 49 |
'account', |
| 49 | 50 |
'box', |
@@ -208,17 +208,17 @@ def wx_order_query_api(request): |
||
| 208 | 208 |
wxpay = WeChatPay(wxcfg.get('appID'), wxcfg.get('apiKey'), wxcfg.get('mchID'))
|
| 209 | 209 |
|
| 210 | 210 |
# 订单查询 |
| 211 |
- data = wxpay.order.query(transaction_id, order_id) |
|
| 211 |
+ query_data = wxpay.order.query(transaction_id, order_id) |
|
| 212 | 212 |
# 签名校验 |
| 213 |
- if not check_signature(data, wxcfg.get('apiKey')):
|
|
| 213 |
+ if not check_signature(query_data, wxcfg.get('apiKey')):
|
|
| 214 | 214 |
return response(OrderStatusCode.SIGN_CHECK_FAIL) |
| 215 | 215 |
|
| 216 |
- order.notify_msg = data |
|
| 217 |
- order.transaction_id = data.get('transaction_id', '')
|
|
| 216 |
+ order.notify_msg = query_data |
|
| 217 |
+ order.transaction_id = query_data.get('transaction_id', '')
|
|
| 218 | 218 |
order.save() |
| 219 | 219 |
|
| 220 | 220 |
# 交易状态 |
| 221 |
- trade_state = data.get('trade_state')
|
|
| 221 |
+ trade_state = query_data.get('trade_state')
|
|
| 222 | 222 |
# 订单状态判断更新 |
| 223 | 223 |
if trade_state == 'SUCCESS': # 订单支付成功 |
| 224 | 224 |
order_paid_success(order) |
@@ -272,20 +272,20 @@ def wx_order_detail_api(request): |
||
| 272 | 272 |
@transaction.atomic |
| 273 | 273 |
def wx_notify_url_api(request): |
| 274 | 274 |
""" 支付异步通知回调地址 """ |
| 275 |
- data, success = check_pay_notify(request.body, wx_configs=settings.WECHAT) |
|
| 275 |
+ notify_data, success = check_pay_notify(request.body, wx_configs=settings.WECHAT) |
|
| 276 | 276 |
if not success: |
| 277 | 277 |
return HttpResponse(WXPAY_NOTIFY_FAIL) |
| 278 | 278 |
|
| 279 | 279 |
try: |
| 280 |
- order = OrderInfo.objects.select_for_update().get(order_id=data.get('out_trade_no', ''), status=True)
|
|
| 280 |
+ order = OrderInfo.objects.select_for_update().get(order_id=notify_data.get('out_trade_no', ''), status=True)
|
|
| 281 | 281 |
except OrderInfo.DoesNotExist: |
| 282 | 282 |
return HttpResponse(WXPAY_NOTIFY_FAIL) |
| 283 | 283 |
|
| 284 | 284 |
order.notify_msg = request.body |
| 285 |
- order.transaction_id = data.get('transaction_id', '')
|
|
| 285 |
+ order.transaction_id = notify_data.get('transaction_id', '')
|
|
| 286 | 286 |
order.save() |
| 287 | 287 |
|
| 288 |
- result_code = data.get('result_code', '')
|
|
| 288 |
+ result_code = notify_data.get('result_code', '')
|
|
| 289 | 289 |
if result_code == 'SUCCESS': |
| 290 | 290 |
order_paid_success(order) |
| 291 | 291 |
else: |
@@ -18,6 +18,7 @@ django-paginator2==1.0.3 |
||
| 18 | 18 |
django-rlog==1.0.7 |
| 19 | 19 |
django-shortuuidfield==0.1.3 |
| 20 | 20 |
django-six==1.0.2 |
| 21 |
+django-we==1.0.1 |
|
| 21 | 22 |
djangorestframework==3.6.3 |
| 22 | 23 |
furl==1.0.0 |
| 23 | 24 |
hiredis==0.2.0 |
@@ -1,4 +0,0 @@ |
||
| 1 |
-from django.contrib import admin |
|
| 2 |
- |
|
| 3 |
- |
|
| 4 |
-# Register your models here. |
@@ -1,4 +0,0 @@ |
||
| 1 |
-from django.db import models |
|
| 2 |
- |
|
| 3 |
- |
|
| 4 |
-# Create your models here. |
@@ -1,4 +0,0 @@ |
||
| 1 |
-from django.test import TestCase |
|
| 2 |
- |
|
| 3 |
- |
|
| 4 |
-# Create your tests here. |
@@ -1,54 +0,0 @@ |
||
| 1 |
-# -*- coding: utf-8 -*- |
|
| 2 |
- |
|
| 3 |
-from django.conf import settings |
|
| 4 |
-from django.shortcuts import redirect |
|
| 5 |
-from furl import furl |
|
| 6 |
-from json_response import auto_response |
|
| 7 |
-from pywe_jssdk import jsapi_signature_params |
|
| 8 |
-from pywe_oauth import get_access_info, get_oauth_code_url, get_userinfo |
|
| 9 |
- |
|
| 10 |
- |
|
| 11 |
-JSAPI = settings.WECHAT.get('JSAPI', {})
|
|
| 12 |
- |
|
| 13 |
- |
|
| 14 |
-def wx_oauth2(request): |
|
| 15 |
- scope = request.GET.get('scope', 'snsapi_userinfo')
|
|
| 16 |
- redirect_url = request.GET.get('redirect_url', '')
|
|
| 17 |
- default_url = request.GET.get('default_url', '')
|
|
| 18 |
- |
|
| 19 |
- if request.weixin: |
|
| 20 |
- redirect_uri = settings.WECHAT_USERINFO_REDIRECT_URI if scope == 'snsapi_userinfo' else settings.WECHAT_BASE_REDIRECT_URI |
|
| 21 |
- return redirect(get_oauth_code_url(JSAPI['appID'], redirect_uri, scope, redirect_url)) |
|
| 22 |
- |
|
| 23 |
- return redirect(default_url or redirect_url) |
|
| 24 |
- |
|
| 25 |
- |
|
| 26 |
-def base_redirect(request): |
|
| 27 |
- code = request.GET.get('code', '')
|
|
| 28 |
- state = request.GET.get('state', '')
|
|
| 29 |
- |
|
| 30 |
- access_info = get_access_info(JSAPI['appID'], JSAPI['appsecret'], code) |
|
| 31 |
- if 'errcode' in access_info: |
|
| 32 |
- return redirect(settings.WECHAT_OAUTH2_RETRY_REDIRECT_URI.format(state)) |
|
| 33 |
- |
|
| 34 |
- return redirect(furl(state).add(access_info).url) |
|
| 35 |
- |
|
| 36 |
- |
|
| 37 |
-def userinfo_redirect(request): |
|
| 38 |
- code = request.GET.get('code', '')
|
|
| 39 |
- state = request.GET.get('state', '')
|
|
| 40 |
- |
|
| 41 |
- access_info = get_access_info(JSAPI['appID'], JSAPI['appsecret'], code) |
|
| 42 |
- if 'errcode' in access_info: |
|
| 43 |
- return redirect(settings.WECHAT_OAUTH2_RETRY_REDIRECT_URI.format(state)) |
|
| 44 |
- |
|
| 45 |
- userinfo = get_userinfo(access_info.get('access_token', ''), access_info.get('openid', ''))
|
|
| 46 |
- if 'openid' not in userinfo: |
|
| 47 |
- return redirect(settings.WECHAT_OAUTH2_RETRY_REDIRECT_URI.format(state)) |
|
| 48 |
- |
|
| 49 |
- return redirect(furl(state).add(userinfo).url) |
|
| 50 |
- |
|
| 51 |
- |
|
| 52 |
-@auto_response |
|
| 53 |
-def wx_jsapi_signature_api(request): |
|
| 54 |
- return jsapi_signature_params(JSAPI['appID'], JSAPI['appsecret'], request.GET.get('url', ''))
|